<template>
  <div>
    <h5>vuex</h5>
    <p style="color:red">{{ count1 }}</p>
    <p style="color:red">{{ count2 }}</p>
    <p style="color:red">{{ doubleCount }}</p>
    <button @click="add1">增加1</button>
    <button @click="add2">增加2</button>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters, mapActions } from 'vuex'
export default {
  name: 'Vuex01',
  computed: {
    ...mapState({
      count2: 'count'
    }),
    ...mapGetters({
      doubleCount: 'doubleCount'
    }),
    count1() {
      return this.$store.state.count
    }
  },
  methods: {
    add1() {
      this.$store.commit('add')
    },
    add2() {
      this.$store.dispatch('delayAdd')
    }
  }
}
</script>
